1
Beyond Constants: The Power of Rust Enums
AI034 Lesson 6
00:00

In Rust, enumerations (enums) are more than simple lists; they are the architectural blueprints of possibility. Unlike loosely grouped integers, an enum is a sum type, meaning a variable can represent exactly one of several distinct variants.

1. Namespacing & Scope

Variants are neatly tucked under the enum's identifier using the double colon (::) operator. This Namespacing prevents collisions across different Modules, Crates, or Packages, allowing you to define a V4 variant in multiple contexts without ambiguity.

Enum Scope: IpAddrKind::V4::V6Mutually Exclusive

2. Type Safety

By using enums as function arguments, the standard library patterns ensure that only valid states enter your logic. This moves potential runtime errors to compile time, ensuring your route function never has to handle a "v5" address that doesn't exist.

main.py
TERMINAL bash — 80x24
> Ready. Click "Run" to execute.
>